package com.smart.comp;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JTextField;

public class TextoNumeros extends JTextField {

    public TextoNumeros() {
        this.addKeyListener(new KeyAdapter() {

            @Override
            public void keyTyped(KeyEvent e) {
                char caracter = e.getKeyChar();
                //int caractern = e.getKeyCode();
                //JOptionPane.showMessageDialog(null, caracter);
                // Verificar si la tecla pulsada no es un digito
                if (((caracter < KeyEvent.VK_0) || (caracter > KeyEvent.VK_9)) && (caracter != KeyEvent.VK_BACK_SPACE)) {
                    e.consume(); // ignorar el evento de teclado
                }
            }
        });

    }
}
